package com.atguigu.cloud.utils;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @Author: huahua
 * @Date: 2024/5/30 0030
 * @Time: 21:18
 * @Description:
 */
@Data
@Accessors(chain = true)
public class ResultData<T> {
    private String code;
    private String message;
    private T data;
    private long timestamp;


    public ResultData() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <V> ResultData<V> success(V data){
        ResultData resultData = new ResultData<>();
        resultData.setCode(ReturnCodeEnum.RC200.getCode());
        resultData.setMessage(ReturnCodeEnum.RC200.getMessage());
        resultData.setData(data);

        return resultData;
    }


    public static <V> ResultData<V> fail(String code,String message){
        ResultData resultData = new ResultData<>();
        resultData.setCode(code);
        resultData.setMessage(message);
        resultData.setData(null);

        return resultData;
    }
}
